package com.iss.airsys.dao;

import com.iss.airsys.entity.Room;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
@Mapper
public interface RoomfreeDao {
    //增
    @Insert("insert into roomfree values(null,#{room_id},#{room_type},#{room_price},#{room_state})")
    Integer insertRoom(Room room);
    //删
    @Delete(" <script>"+"delete from roomfree where room_id in" +
            "    <foreach collection=\"array\" item=\"id\" separator=\",\" open=\"(\" close=\")\">" +
            "        #{id}" +
            "    </foreach></script>")
     Integer deletRoom(String[]room_ids);
    //改
    @Update("update roomfree set room_type=#{room_type},room_price=#{room_price},room_state=#{room_state} where room_id=#{room_id}")
     Integer updateRoom(Room room);
    //根据房间号查
    @Select("select room_id,room_type,room_price,room_state from roomfree where room_id=#{room_id}")
     Room selectRoom(String room_id);
    //查询全部
    @Select("<script>select * from roomfree" +
            "<where>" +
            "<if test='priceFrom!=null'> and room_price &gt;= #{priceFrom}</if>" +
            "<if test='priceTo!=null'> and room_price &lt;= #{priceTo}</if>"+
            "</where>" +
            "</script>")
     List<Room> selectAll(@Param("priceFrom")Double priceFrom,@Param("priceTo")Double priceTo);
    //查询全部房间号
    @Select("select room_id from roomfree")
     List<String> selectRoomid();
    //改房间的状态
    @Update("update roomfree set room_state=#{room_state} where room_no=#{room_no}")
    Integer updateRoomState(@Param("room_state") String room_state,@Param("room_no") String room_no);
    //根据id查询状态
    @Select("select room_state from roomfree where room_no=#{room_no}")
    String selectRoomState(@Param("room_no")String room_no);

    @Delete(" <script>"+"update roomfree set room_state='空闲' where room_no in" +
            "    <foreach collection=\"array\" item=\"id\" separator=\",\" open=\"(\" close=\")\">" +
            "        #{id}" +
            "    </foreach></script>")
    Integer CheckoutRoom(Integer[] Checkout_room);
    @Update("update guest set guest_checkouttime=#{guest_checkouttime} where guest_id=#{guest_id}")
    Integer updateCheckouttime();
}
